/**
 * Copyright (c) 2009 Cycle Information Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to the following 
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies 
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * 
 */
package com.cycleit.cycleframework.exception {
	
	import mx.utils.StringUtil;
	
	/**
	 * Clase de error lanzada cuando sucede un problema en el CycleFramework.
	 */
	public class CycleException extends Error {
	   public static const SINGLETON_EXCEPTION : String = "Instance cannot be instantiated for {0}";
	   public static const COMMAND_ALREADY_REGISTERED : String = "Command already registered for {0}";
	   public static const COMMAND_NOT_FOUND : String = "Command not found for {0}";
	   public static const VIEW_ALREADY_REGISTERED : String = "View already registered for {0}";
	   public static const VIEW_NOT_FOUND : String = "View not found for {0}";
	   public static const REMOTE_OBJECT_NOT_FOUND : String = "RemoteObject not found for {0}";	
	   public static const HTTP_SERVICE_NOT_FOUND : String = "HTTPService not found for {0}";
	   public static const WEB_SERVICE_NOT_FOUND : String = "WebService not found for {0}";
	   public static const CONSUMER_NOT_FOUND : String = "Consumer not found for {0}";
	   public static const PRODUCER_NOT_FOUND : String = "Producer not found for {0}";
	   public static const DATA_SERVICE_NOT_FOUND : String = "DataService not found for {0}";
	   public static const ABSTRACT_METHOD_CALLED : String = "Abstract method called {0}";
	   public static const COMMAND_NOT_REGISTERED : String = "Command not registered for {0}";
	   public static const COMMAND_REF_NULL : String = "The 'commandRef' argument cannot be null";
	   public static const COMMAND_SHOULD_IMPLEMENT_ICOMMAND : String = "Command should implement ICommand interface";
	   public static const COMMAND_NAME_NULL : String = "The 'commandName' argument cannot be null";
	   public static const NEED_HOST : String = "The 'host' argument cannot be null";
	   public static const NEED_PROPERTY : String = "The 'property' argument cannot be null";
	   public static const NEED_NAVIGATION : String = "The 'navigation' argument cannot be null";
       public static const NAVIGATION_ALREADY_EXIST : String = "Navigation already registered for {0}";
	   public static const MAIN_CONTAINER_NEEDED:String = "Main cointainer cannot be null";
	   public static const NEED_SERVICE : String = "The 'service' argument cannot be null";
	   public static const NEED_HANDLER : String = "The 'handler' argument cannot be null";
	   public static const SERVICE_ALREADY_EXIST : String = "Service already registered for {0}";
	   public static const SERVICE_NOT_FOUND : String = "Service not found for {0}";
				
	 	public function CycleException( errorCode : String, ... rest ) {
			super( formatMessage( errorCode, rest.toString() ) );
		}
		
		private function formatMessage( errorCode : String, ... rest ) : String	{
			var message : String =  StringUtil.substitute( errorCode, rest );			
			return StringUtil.substitute( "{0}: {1}", errorCode, message);
		}
		
	}
}